package cn.com.my.yzt;

import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.lang.StringUtils;
import org.junit.Test;

public class TestYzt {

	@Test
	public void TestReplace(){
	//	String url = "www.asd.com/?userid={userid}&password={password}";
	//	String[] values = {"123","321"};
		
		String url = "尊敬的{1}，您好！<br/>"
				+"用户{2}预约了您{3}{4}的{5}专题服务。<br/>"
				+"用户联系方式：{6}。<br/>"
				+"症状描述：{7}。"
				+ "<p>请快去处理订单吧。<p/>"
				+"<br/><br/><br/><br/>健康通运营团队<br/> --------------------------------------------<br/>"
				+"<img width=\"100px\" height=\"auto\" src=\"{8}\" />";
		String[] values = new String[]{null, "b", "c", "d", "e", "f", "g", "h"};
		
		String regex = "\\{[^\\{\\}]*\\}";
		Pattern pt = Pattern.compile(regex);
		Matcher match = pt.matcher(url);
		int i = 0;
		while(match.find()) {
			String paramValue = match.group();
			url = url.replaceAll(paramValue.replaceAll("\\{", "\\\\{").replaceAll("\\}", "\\\\}"), values[i]);
			i++;
		}
		System.out.println("url ===="+url);
	}
}	
